/**
 * 上午11:48:31
 */
package com.hsnn.medstgmini.base.std.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hsnn.medstgmini.base.std.dao.StdCompdrugprofileDao;
import com.hsnn.medstgmini.base.std.dao.StdDrugcatalogDao;
import com.hsnn.medstgmini.base.std.model.StdCompdrugprofile;
import com.hsnn.medstgmini.base.std.model.StdCompdrugprofileLog;
import com.hsnn.medstgmini.base.std.service.StdCompdrugprofileManager;
import com.hsnn.medstgmini.dao.HibernateSqlUtil;
import com.hsnn.medstgmini.util.Pagination;

/**
 * @author hsnn
 *
 */
@Service
public class StdCompdrugprofileManagerImpl implements StdCompdrugprofileManager {

	@Autowired
	private StdCompdrugprofileDao StdCompdrugprofileDao;

	@Autowired
	private StdDrugcatalogDao stdDrugcatalogDao;

	@Autowired
	private HibernateSqlUtil hibernateSqlUtil;
	
	
	
	@Override
	public List<StdCompdrugprofile> getStdCompdrugprofileByName(String name) {
		return StdCompdrugprofileDao.getStdCompdrugprofileByName(name);
	}

	@Override
	public boolean update(Object entity) {
		if (hibernateSqlUtil.update(entity)){
			return true;
		}
		return false;
		
	}

	@Override
	public boolean save(Object entity) {
		
		if (hibernateSqlUtil.add(entity)){
			return true;
		}
		return false;
	}

	@Override
	public Pagination getStdCompdrugprofileList(Pagination page) {
		return StdCompdrugprofileDao.getStdCompdrugprofileList(page);
	}

	/**
	 * 获取药品资质信息
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Pagination getStdCompdrugprofileLogList(Pagination page) {
		List<Object> list = StdCompdrugprofileDao.getStdCompdrugprofileLogList(page);
		Map<String,String> map = new HashMap<String, String>();
		for(int i = 0;i<list.size();i++){
			map = (Map<String, String>) list.get(i);
			
			String detail = map.get("detail");
			if( StringUtils.isNotBlank(detail)){
				if(detail.toString().indexOf(",")<0){
					detail = "新增资质:<br/>".concat(detail.replaceAll(";", "<br/>"));
					
				}else{
					detail= detail.replaceAll(":", "由");
					detail= detail.replaceAll(",", "变为");
					detail= detail.replaceAll(";", "<br/>");
				}
			}
			map.put("detail", detail);
		}
		page.setRows(list);
		return page;
	}

	@Override
	public Object getUniquerResult(Class<?> entity, String key, String value) {
		return stdDrugcatalogDao.getUniquerResult(entity, key, value);
	}
	
	/**
	 * @category 查询维护日志详情
	 * @date 2015年9月28日
	 * @param compprofileId
	 * @return
	 */
	public List<Map<String, Object>> getDrugProfileLogDetail(String logId) {
		return StdCompdrugprofileDao.getDrugProfileLogDetail(logId);
	}

	/**
	 * @category 保存药品资质日志信息
	 * @author 韩守松
	 * @date   2015年10月26日
	 * @param  @param stdCompdrugprofileLog
	 * @param  @return
	 */
	public boolean saveLog(StdCompdrugprofileLog stdCompdrugprofileLog){
		return StdCompdrugprofileDao.saveLog(stdCompdrugprofileLog);
	}
}
